package unicall.em.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import unicall.em.models.SipAccount;
import unicall.em.models.vo.SipAccountQuery;
import unicall.em.services.SipAccountService;
import unicall.em.utils.Constant;

@RestController
@RequestMapping(value = "/account")
public class SipAccounts {

    @Autowired
    private SipAccountService service;

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(@ModelAttribute("query") SipAccountQuery query,@RequestParam(required=false,value="pageNumber",defaultValue="0")int pageNumber) {
        ModelAndView mv = new ModelAndView();
        Page<SipAccount> page = service.queryAll(query.toSpec(), new PageRequest(pageNumber,Constant.PAGE_SIZE));
        mv.addObject("page", page);
        mv.setViewName("/accounts/index");
        return mv;
    
    }


}
